﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Collections.Generic;

namespace Xceed.Silverlight.Data
{
  internal abstract class PeekableCacheEnumerator : CacheEnumerator, IPeekableEnumerator<DataPath>
  {
    #region Constructor

    protected PeekableCacheEnumerator(
      IAsyncEnumerator<DataPath> childEnumerator,
      IContextualCompareHelper compareHelper,
      IContextualItemHelper itemHelper,
      int cacheSize )
      : base( childEnumerator, compareHelper, itemHelper, cacheSize )
    {
    }

    #endregion

    #region IPeekableEnumerator Members

    public PeekResult<DataPath> Peek( PeekParameters parameters )
    {
      long actualSkipCount;
      IList<DataPath> peekedItems;
      SourcePosition endPosition;
      Nullable<int> sourcePositionIndex;
      bool operationCompleted;
      RelativeOffset endPositionOffset;
      EstimateInt64 totalCount;

      this.CacheJumpMoveAndFetch(
        parameters.ConvertToJumpMoveAndFetchParameters(),
        out actualSkipCount,
        out peekedItems,
        out endPosition,
        out sourcePositionIndex,
        out operationCompleted,
        out endPositionOffset,
        out totalCount );

      return new PeekResult<DataPath>(
        parameters.SourcePosition,
        parameters.ApproximateSkip,
        parameters.ExpectedSkipCount,
        parameters.ExpectedPeekCount,
        actualSkipCount,
        peekedItems,
        endPosition,
        endPositionOffset,
        totalCount );
    }

    #endregion
  }
}
